package com.atguigu.spzx.product.controller;

import com.atguigu.spzx.model.entity.product.Category;
import com.atguigu.spzx.model.entity.product.ProductSku;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.h5.IndexVo;
import com.atguigu.spzx.product.service.CategoryService;
import com.atguigu.spzx.product.service.ProductSkuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@Tag(name="用户首页模块")
@RestController
@RequestMapping("/api/product/index")
//@CrossOrigin
public class IndexController {
    @Resource
    CategoryService categoryService;
    @Resource
    ProductSkuService productSkuService;
    @Operation(summary = "查询首页分类和畅销商品列表")
    @GetMapping
    public Result<IndexVo> index(){
        //调用业务层查询首页需要的一级分类列表
        List<Category> categoryList = categoryService.findOneCategories();
        //调用业务层查询首页需要的热门sku数据列表   根据sale_num排序 查询前20条
        List<ProductSku> productSkuList  = productSkuService.findProductSkusBySaleNum();
        //将上面的数据封装为一个IndexVo类的对象响应
        IndexVo indexVo = new IndexVo();
        indexVo.setCategoryList(categoryList);
        indexVo.setProductSkuList(productSkuList);
        return Result.ok(indexVo);
    }
}
